/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Estudiantes_asesor.java
 *
 * Created on Jul 21, 2011, 8:00:23 PM
 */
package Asesor;

import ClasesVarias.MiModelo;
import callProcs.ProcsAsesores;
import callProcs.ProcsJMOC;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
 *
 * @author Juls
 */
public class Estudiantes_asesor extends javax.swing.JFrame {
 ProcsAsesores VerAsesor =new ProcsAsesores();
 ProcsJMOC verEst_As=new ProcsJMOC();
        java.sql.ResultSet rs;
        List lista = new ArrayList();        
        Integer cont=0;
        Integer indice=0;
        
    /** Creates new form Estudiantes_asesor */
    public Estudiantes_asesor() {
        initComponents();
        cargaasesores();
        //TableEstudAsig.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ComboAsesor_EstAs = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TableEstudAsig = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bufete.BufeteApp.class).getContext().getResourceMap(Estudiantes_asesor.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        ComboAsesor_EstAs.setName("ComboAsesor_EstAs"); // NOI18N
        ComboAsesor_EstAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboAsesor_EstAsActionPerformed(evt);
            }
        });

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        TableEstudAsig.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Carne", "Nombre", "Apellido", "Telefono"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        TableEstudAsig.setName("TableEstudAsig"); // NOI18N
        jScrollPane1.setViewportView(TableEstudAsig);
        TableEstudAsig.getColumnModel().getColumn(0).setMinWidth(100);
        TableEstudAsig.getColumnModel().getColumn(0).setMaxWidth(100);
        TableEstudAsig.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("TableEstudAsig.columnModel.title0")); // NOI18N
        TableEstudAsig.getColumnModel().getColumn(1).setMinWidth(200);
        TableEstudAsig.getColumnModel().getColumn(1).setMaxWidth(200);
        TableEstudAsig.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("TableEstudAsig.columnModel.title1")); // NOI18N
        TableEstudAsig.getColumnModel().getColumn(2).setMinWidth(200);
        TableEstudAsig.getColumnModel().getColumn(2).setMaxWidth(200);
        TableEstudAsig.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("TableEstudAsig.columnModel.title2")); // NOI18N
        TableEstudAsig.getColumnModel().getColumn(3).setMinWidth(100);
        TableEstudAsig.getColumnModel().getColumn(3).setMaxWidth(100);
        TableEstudAsig.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("TableEstudAsig.columnModel.title3")); // NOI18N

        jLabel3.setIcon(resourceMap.getIcon("jLabel3.icon")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("jButton1.toolTipText")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(597, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(ComboAsesor_EstAs, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(328, Short.MAX_VALUE)
                        .addComponent(jLabel1)))
                .addGap(206, 206, 206))
            .addGroup(layout.createSequentialGroup()
                .addGap(52, 52, 52)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 601, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(82, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ComboAsesor_EstAs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jButton1))
                .addGap(62, 62, 62)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

       public void cargaasesores(){
        
          try {
           rs= VerAsesor.verAsesores("");
            while (rs.next()){
                String nom=rs.getObject("nombrec").toString();
                String idase=rs.getObject("IdAsesor").toString();
                String cad=idase+"."+nom;
                 ComboAsesor_EstAs.addItem(nom);
                 lista.add(cont,idase);
                 //JOptionPane.showMessageDialog(null, lista.get(cont).toString());
                 cont++;  
            }
        } catch (SQLException ex) {
            Logger.getLogger(BuscarEditar_asesor.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }     
    
    private void ComboAsesor_EstAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboAsesor_EstAsActionPerformed
        // TODO add your handling code here:+
         indice=ComboAsesor_EstAs.getSelectedIndex();
       // JOptionPane.showMessageDialog(null,String.valueOf(indice));
        TableEstudAsig.setVisible(true);
    }//GEN-LAST:event_ComboAsesor_EstAsActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        
                 Vector tableData = new Vector();
    Vector<String> tableHeaders = new Vector<String>();
    
    tableHeaders.add("Carne Estudiante"); 
    tableHeaders.add("Nombre Estudiante");
    tableHeaders.add("Apellido Estudiante");
    
    
     Vector<Object> oneRow = null; 
        
        try {
           rs= verEst_As.busca_alumnos_ases(lista.get(indice).toString());
            while (rs.next()){
                String car=rs.getObject("NoCarne").toString();
                String nom=rs.getObject("Nombre_estudiante").toString();
                String ape=rs.getObject("Apellido_estudiante").toString();
                
                oneRow = new Vector<Object>();
                oneRow.add(car);
                oneRow.add(nom);
                oneRow.add(ape);
        
        tableData.add(oneRow);
    }
    //jTable2.setModel(new DefaultTableModel(tableData, tableHeaders));
    //MiModelo modelo = new MiModelo();
    TableEstudAsig.setModel(new MiModelo(tableData, tableHeaders));  
        } catch (SQLException ex) {
            Logger.getLogger(BuscarEditar_asesor.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }//GEN-LAST:event_jButton1ActionPerformed

   
    public void llenartabla(){
      
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Estudiantes_asesor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ComboAsesor_EstAs;
    private javax.swing.JTable TableEstudAsig;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
